package com.lujianfei.netease_android_mvvm_kotlin.base

import androidx.appcompat.app.AppCompatActivity
import kotlinx.coroutines.*

open class BaseActivity : AppCompatActivity(),CoroutineScope by MainScope() {

    fun launchOnUI(block: suspend CoroutineScope.() -> Unit) {
        launch(Dispatchers.Main) {
            block()
        }
    }

    fun launchOnIO(block: suspend CoroutineScope.() -> Unit) {
        launch(Dispatchers.IO) {
            block()
        }
    }

    override fun onDestroy() {
        super.onDestroy()
        cancel()
    }
}